// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.characters.AttachedItems;

import java.util.ArrayList;
import zombie.inventory.types.HandWeapon;
import zombie.inventory.types.WeaponPart;
import zombie.scripting.objects.ModelWeaponPart;
import zombie.util.StringUtils;
import zombie.util.Type;

public final class AttachedModelNames {
    protected AttachedLocationGroup group;
    protected final ArrayList<AttachedModelName> models = new ArrayList();

    AttachedLocationGroup getGroup() {
        return this.group;
    }

    public void copyFrom(AttachedModelNames other) {
        this.models.clear();

        for (int _int = 0; _int < other.models.size(); _int++) {
            AttachedModelName attachedModelName = (AttachedModelName)other.models.get(_int);
            this.models.add(new AttachedModelName(attachedModelName));
        }
    }

    public void initFrom(AttachedItems attachedItems) {
        this.group = attachedItems.getGroup();
        this.models.clear();

        for (int int0 = 0; int0 < attachedItems.size(); int0++) {
            AttachedItem attachedItem = attachedItems.get(int0);
            String string0 = attachedItem.getItem().getStaticModel();
            if (!StringUtils.isNullOrWhitespace(string0)) {
                String string1 = this.group.getLocation(attachedItem.getLocation()).getAttachmentName();
                HandWeapon handWeapon = Type.tryCastTo(attachedItem.getItem(), HandWeapon.class);
                float _float = handWeapon == null ? 0.0F : handWeapon.getBloodLevel();
                AttachedModelName attachedModelName0 = new AttachedModelName(string1, string0, _float);
                this.models.add(attachedModelName0);
                if (handWeapon != null) {
                    ArrayList arrayList0 = handWeapon.getModelWeaponPart();
                    if (arrayList0 != null) {
                        ArrayList arrayList1 = handWeapon.getAllWeaponParts();

                        for (int int1 = 0; int1 < arrayList1.size(); int1++) {
                            WeaponPart weaponPart = (WeaponPart)arrayList1.get(int1);

                            for (int int2 = 0; int2 < arrayList0.size(); int2++) {
                                ModelWeaponPart modelWeaponPart = (ModelWeaponPart)arrayList0.get(int2);
                                if (weaponPart.getFullType().equals(modelWeaponPart.partType)) {
                                    AttachedModelName attachedModelName1 = new AttachedModelName(
                                        modelWeaponPart.attachmentNameSelf, modelWeaponPart.attachmentParent, modelWeaponPart.modelName, 0.0F
                                    );
                                    attachedModelName0.addChild(attachedModelName1);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public int size() {
        return this.models.size();
    }

    public AttachedModelName get(int index) {
        return (AttachedModelName)this.models.get(index);
    }

    public void clear() {
        this.models.clear();
    }
}
